package com.lm.mapper;

import com.lm.pojo.Lecture;
import tk.mybatis.mapper.common.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import java.util.List;

@org.apache.ibatis.annotations.Mapper
public interface LectureMapper extends Mapper<Lecture> {
    @Select("SELECT * FROM ylb_lecture WHERE id IN (SELECT lecture_id FROM ylb_lecture_booking WHERE user_nickname = #{nickname})")
    List<Lecture> getUserBookings(String nickname);

    @Select("SELECT COUNT(*) FROM ylb_lecture_booking WHERE lecture_id = #{lectureId} AND user_nickname = #{nickname}")
    boolean checkBooking(Long lectureId, String nickname);

    @Delete("DELETE FROM ylb_lecture_booking WHERE lecture_id = #{lectureId} AND user_nickname = #{nickname}")
    void deleteBooking(Long lectureId, String nickname);

    @Insert("INSERT INTO ylb_lecture_booking (lecture_id, user_nickname) VALUES (#{lectureId}, #{nickname})")
    void addBooking(Long lectureId, String nickname);

    @Select("SELECT * FROM ylb_lecture WHERE category = #{category}")
    List<Lecture> selectByCategory(String category);

    @Select("SELECT * FROM ylb_lecture WHERE title LIKE #{title}")
    List<Lecture> searchByTitle(String title);

    @Delete("DELETE FROM ylb_lecture_booking WHERE lecture_id = #{lectureId}")
    void deleteAllBookings(Long lectureId);
}